package com.fairytask.ui
{
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.base.FrameUI;
	import com.fairytask.ui.effect.MoneyEffect;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	/**
	 * 炼金炉 
	 * @author zhut
	 * 
	 */	
	public class AlchemyUT extends FrameUI
	{
		private static var _self	:AlchemyUT;
		
		public var alchemyBG	:MovieClip;
		public var infoBG		:MovieClip;
		public var alchemy		:Clip;
		public var submit		:Button;
		public var info		:Label;
		public var useInfo		:Label;
		
//		private const _freeTime	:int=1;	//第一次免费
		private var _count		:int;
		private var _level		:int;
		private var _hasGold	:int;
		private var _needGold	:int;
		private var _getSilver	:int;
		//动画用
		private var _moneyEffect	:MoneyEffect;
		
		public function AlchemyUT(popUI:Boolean=true)
		{
			super(popUI);
			init();
			initView()
			initEvent();
		}
		public static function  getInstance():AlchemyUT
		{
			if(_self==null)
			{
				_self=new AlchemyUT();
				
			}
			return _self;
		}
		//初始化
		private function init():void
		{
			
		}
		//初始化视图
		private function initView():void
		{
			/*bindManager.BindViewProp(model.scene.GetView(ViewDefine.VIEWPORT_PACKAGE),"Gold",setGold);
			bindManager.BindProp(Player.getInstance().data,"Level",this,"pLevel");
			bindManager.BindProp(Player.getInstance().data,"CollectCount",this,"pCollectCount");*/
		}
		
		//初始化事件
		private function initEvent():void
		{
			submit.addEventListener(MouseEvent.CLICK,onaddMoney);
			/*model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_ALCHEMY,onAlchemy);
			model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_ALCHEMY_GET,onGetMoney);*/
		}
		
		/**
		 * 成功炼金 
		 * @param event
		 * 
		 */
		/*protected function onGetMoney(evt:CustomToClientEvent):void
		{
			//获取银两
			var moneyVal	:int	=	evt.pList.shift();	//暂时不用
			//银两动画
			_moneyEffect = new MoneyEffect(MoneyDefine.CAPITAL_TYPE_SILVER, this.x + 160, this.y + 170, onMoneyPlayOver);
			_moneyEffect.show();
			//炼金炉特效
			TweenMax.to(alchemy, 1, {glowFilter:{color:0xFF0000, alpha:0.7, blurX:30, blurY:30, strength:2, quality:1},repeat:1,yoyo:true,startAt:{glowFilter:{color:0xFF0000, alpha:0, blurX:0, blurY:0, strength:1, quality:1}}});
		}*/
		
		/**
		 * 播放完动画 
		 * 
		 */
		private function onMoneyPlayOver():void
		{
			_moneyEffect.hide();
		}
		
		/**
		 * 现有的仙玉 
		 * @param key
		 * @param val
		 * 
		 */
		private function setGold(key:String,val:int):void
		{
			_hasGold = val;
			setTxtColor();
		}
		
		/**
		 *  获取人物等级
		 * @param val
		 * 
		 */
		public function set pLevel(val:int):void
		{
			_level=val;	
			setTxtColor();
		}
		
		/**
		 * 获取炼金次数
		 * @param val
		 * 
		 */
		public function set pCollectCount(val:int):void
		{ 
			_count=val;	
			setTxtColor();
		}
		
		/**
		 * 炼金炉信息 
		 * @param evt
		 * 
		 */
		/*private function onAlchemy(evt:CustomToClientEvent):void
		{
			_needGold	= evt.pList.shift();
			_getSilver	= evt.pList.shift();
			setTxtColor();
		}*/
		
		/**
		 * 刷新仙玉颜色 
		 * 
		 */
		private function setTxtColor():void
		{
			var needStr	:String;
			if(_needGold > _hasGold)
			{
				needStr = "<font color='#FF0000'>"+_needGold+"</font>";
			}
			else
			{
				needStr = "<font color='#00CD00'>"+_needGold+"</font>";
			}
			info.htmlStrByBorder=StaticIni.getSwfLangStrVar("1000000019",[needStr,_getSilver]);;	
		}
		//实现监听函数
		private function onaddMoney(e:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ALCHEMY);
//			submit.enabled = false;
		}
		
		/**
		 * 打开 
		 * @param space
		 * @param onshow
		 * 
		 */
		override public function show(space:String=MIDDLELAYER, onshow:Function=null):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_OPEN_ALCHEMY);
//			submit.enabled = true;
			super.show(space,onshow);
		}
		
		override public function hide(e:*=null):void
		{
			super.hide();
		}
	}
}